﻿using System;
using System.Windows.Controls;

namespace YanZhiwei.DotNet3._5.Utilities.WPF
{
    /// <summary>
    /// WPF-TextBlock的帮助类
    /// </summary>
    public static class TextBlockHelper
    {
        #region 设置TextBlock的文本内容，线程安全
        /// <summary>
        /// 设置TextBlock的文本内容，线程安全
        /// </summary>
        /// <param name="textBlock">TextBlock</param>
        /// <param name="input">文本内容</param>
        public static void SetTextTF(this TextBlock textBlock, string input)
        {
            textBlock.Dispatch(txt => txt.Text = input);
        }
        /// <summary>
        /// 设置TextBlock的文本内容，线程安全
        /// </summary>
        /// <param name="textBlock">TextBlock</param>
        /// <param name="input">文本内容</param>
        /// <param name="condition">检查条件</param>
        public static void SetTextTF(this TextBlock textBlock, string input, bool condition)
        {
            if (condition)
            {
                SetTextTF(textBlock, input);
            }
        }
        /// <summary>
        /// 设置TextBlock的文本内容，线程安全
        /// </summary>
        /// <param name="textBlock">TextBlock</param>
        /// <param name="input">文本内容</param>
        /// <param name="conditionHanlder">检查条件</param>
        public static void SetTextTF(this TextBlock textBlock, string input, Func<TextBlock, bool> conditionHanlder)
        {
            if (conditionHanlder(textBlock))
            {
                SetTextTF(textBlock, input);
            }
        }
        #endregion 
    }
}
